// c:\Users\Administrator\Desktop\hahah\toutiao\pages\xiangqing\xiangqing.js
Page({
  data: {
    vote_option: '',
    xiangqing: '',
    id: '',
    renwuid: '',
    dameinv: [],
    a: ''
    ,
    user: '',
    c_id: ''
  },
  onLoad: function (e) {
    this.setData({
      renwuid: e.id
    })
  },
  onShow: function () {
    const user = tt.getStorageSync('meinv')
    this.setData({
      user: user
    })
    this.chuio()
  },
  chuio() {
    tt.request({
      url: 'https://ceshi666.yxbnet.cn/api/Rota/modulardetails',
      data: {
        id: this.data.renwuid,
        userid: this.data.user.id
      },
      method: 'POST',
      success: res => {
        console.log('详情',res);
        this.setData({
          xiangqing: res.data.data,
          c_id: res.data.data.c_id,
          id: this.data.renwuid,
          dameinv: res.data.data.vote_option,
          a: res.data.data,
          renwuid: this.data.renwuid
        })
      }
    })
  },
  changetype(type) {
    var _this = this
    console.log(type);
    this.setData({
      vote_option: type.currentTarget.dataset.type
    })

    const user=tt.getStorageSync('token')
    // 选择 
    if(!user){
      tt.showModal({
        title:'请登录',
        showCancel: false,
        success(res) {
          tt.switchTab({
            url:'../my/my'
          })
        }
      })
      }else{
        tt.request({
          url: 'https://ceshi666.yxbnet.cn/api/Rota/addvote',
          data: {
            listid: this.data.id,
            userid: this.data.user.id,
            option: this.data.vote_option
          },
          method: 'POST',
          success: res => {
            console.log(777, res);
            if (res.data.code == 1) {
              tt.showToast({
                title: '投票成功'
              })
              _this.chuio()
            } else {
              tt.showToast({
                title: '您已进行投票'
              })
            }
    
          }
        })
      }

    



  },

  // 上下
  shangxia(e) {
    tt.request({
      url: 'https://ceshi666.yxbnet.cn/api/Rota/limit',
      data: {
        userid: this.data.user.id,
        id: this.data.id,
        type: e.currentTarget.dataset.lala,
        c_id: this.data.c_id
      },
      method: 'POST',
      success: res => {
        console.log(990, res);
        if (res.data.code == 0) {
          tt.showToast({
            title: res.data.msg
          })

          tt.request({
            url: 'https://ceshi666.yxbnet.cn/api/Rota/modulardetails',
            data: {
              id: res.data.data.id,
              userid: this.data.user.id
            },
            method: 'POST',
            success: res => {
              console.log(888, res);
              this.setData({
                xiangqing: res.data.data,
                id: this.data.renwuid,
                dameinv: res.data.data.vote_option,
                a: res.data.data,
                renwuid: this.data.renwuid,
                c_id: res.data.data.c_id,

              })
            }
          })
        }
        tt.request({
          url: 'https://ceshi666.yxbnet.cn/api/Rota/modulardetails',
          data: {
            id: res.data.data.id,
            userid: this.data.user.id
          },
          method: 'POST',
          success: res => {
            console.log(888, res);
            this.setData({
              xiangqing: res.data.data,
              id: this.data.renwuid,
              dameinv: res.data.data.vote_option,
              a: res.data.data,
              renwuid: this.data.renwuid,
              c_id: res.data.data.c_id,

            })
          }
        })
        this.setData({
          renwuid: res.data.data.id
        })

        this.setData({
          xiangqing: res.data.data,
          id: res.data.data.id
        })
      }
    })
  },



  // 分享
  onShareAppMessage(res) {
    const xiaojiang=this.data.xiangqing;
    console.log(676,this.data.xiangqing);
    const oo=this.data.renwuid
    return {
      desc:xiaojiang.coun,
      title:xiaojiang.vato_name,
      imageUrl:xiaojiang.vote_image,
      path: '/pages/xiangqing/xiangqing?id='+oo
    }
  },



  // 广告
  adloadhandler(e) {
    console.log("广告加载成功");
  },
  aderrorhandler(e) {
    console.log("广告加载失败", e);
    tt.showToast({
      title: "广告加载失败" + e.errMsg,
      icon: "fail",
    });
  },
  adclosehandler(e) {
    console.log("广告关闭");
  },
})